home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / phpMyAdmin / libraries / server_privileges.js < prev    next >
Text File  |  2004-04-02  |  3KB  |  89 lines

  1. /* $Id: server_privileges.js,v 2.1 2004/04/03 00:29:59 swix Exp $ */
  2.  
  3.  
  4. /**
  5.  * Validates the password field in a form
  6.  *
  7.  * @param   object   the form
  8.  *
  9.  * @return  boolean  whether the field value is valid or not
  10.  */
  11. function checkPassword(the_form)
  12. {
  13.     // Did the user select 'no password'?
  14.     if (typeof(the_form.elements['nopass']) != 'undefined' && the_form.elements['nopass'][0].checked) {
  15.         return true;
  16.     } else if (typeof(the_form.elements['pred_password']) != 'undefined' && (the_form.elements['pred_password'].value == 'none' || the_form.elements['pred_password'].value == 'keep')) {
  17.         return true;
  18.     }
  19.  
  20.     // Validates
  21.     if (the_form.elements['pma_pw'].value == '') {
  22.         alert(jsPasswordEmpty);
  23.         the_form.elements['pma_pw2'].value = '';
  24.         the_form.elements['pma_pw'].focus();
  25.         return false;
  26.     } else if (the_form.elements['pma_pw'].value != the_form.elements['pma_pw2'].value) {
  27.         alert(jsPasswordNotSame);
  28.         the_form.elements['pma_pw'].value  = '';
  29.         the_form.elements['pma_pw2'].value = '';
  30.         the_form.elements['pma_pw'].focus();
  31.         return false;
  32.     } // end if...else if
  33.  
  34.     return true;
  35. } // end of the 'checkPassword()' function
  36.  
  37.  
  38. /**
  39.  * Validates the "add a user" form
  40.  *
  41.  * @return  boolean  whether the form is validated or not
  42.  */
  43. function checkAddUser(the_form)
  44. {
  45.     if (the_form.elements['pred_hostname'].value == 'userdefined' && the_form.elements['hostname'].value == '') {
  46.         alert(jsHostEmpty);
  47.         the_form.elements['hostname'].focus();
  48.         return false;
  49.     }
  50.  
  51.     if (the_form.elements['pred_username'].value == 'userdefined' && the_form.elements['username'].value == '') {
  52.         alert(jsUserEmpty);
  53.         the_form.elements['username'].focus();
  54.         return false;
  55.     }
  56.  
  57.     return checkPassword(the_form);
  58. } // end of the 'checkAddUser()' function
  59.  
  60.  
  61. /**
  62.  * Checks/unchecks all checkboxes
  63.  *
  64.  * @param   string   the form name
  65.  * @param   atring   the name of the array with the checlboxes
  66.  * @param   boolean  whether to check or to uncheck the element
  67.  *
  68.  * @return  boolean  always true
  69.  */
  70. function setCheckboxes(the_form, the_checkboxes, do_check)
  71. {
  72.     var elts      = (the_checkboxes != '')
  73.                   ? document.forms[the_form].elements[the_checkboxes + '[]']
  74.                   : document.forms[the_form].elements;
  75.     var elts_cnt  = (typeof(elts.length) != 'undefined')
  76.                   ? elts.length
  77.                   : 0;
  78.  
  79.     if (elts_cnt) {
  80.         for (var i = 0; i < elts_cnt; i++) {
  81.             elts[i].checked = do_check;
  82.         } // end for
  83.     } else {
  84.         elts.checked        = do_check;
  85.     } // end if... else
  86.  
  87.     return true;
  88. } // end of the 'setCheckboxes()' function
  89.